#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <mh/common.h>
#include <mh/sram.h>
#include "knit.h"
#include "prefixknit.h"
#include "backpiece.h"

/** \brief  :获取花样的边界，不包含F色码
 *
 * \param   :none
 * \return  :none
 * \date    :2014\02\10
 * \author  :haoyaoyao
 */
void SetFlowerBoundary(MH_KNIT *p)
{
    int i = 0;
    int j = 0;
    int width = p->flower_width;
    int height = p->flower_height;

    if(!p->flower_data)
    {
        return;
    }

    for (j = 0; j < width; j++)
    {
        for (i = 0; i < height; i++)
        {
            uchar color = p->flower_data[i * width + j];
            if ((color != 0) && (color != 0x0F))
            {
                p->left_bound = j;
                goto FIND_RIGHT_BOUND;
            }
        }
    }

FIND_RIGHT_BOUND:

    for (j = width - 1; j >= 0; j--)
    {
        for (i = 0; i < height; i++)
        {
            uchar color = p->flower_data[i * width + j];
            if ((color != 0) && (color != 0x0F))
            {
                p->right_bound = j;
                return;
            }
        }
    }
}
